/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.siox.util.UI;

import java.awt.Dimension;
import java.awt.Toolkit;

/**
 *
 * @author Lindily
 */
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;

public class ToCenter {

    public static void mediate(Container c) {
        Toolkit kit = Toolkit.getDefaultToolkit();    // 定义工具包
        Dimension screenSize = kit.getScreenSize();   // 获取屏幕的尺寸
        int screenWidth = screenSize.width / 2;         // 获取屏幕的宽
        int screenHeight = screenSize.height / 2;       // 获取屏幕的高
        int height = c.getHeight();
        int width = c.getWidth();
        c.setLocation(screenWidth - width / 2, screenHeight - height / 2);
    }

    public static void mediate(Frame f) {
        f.setLocationRelativeTo(null);
    }

    public static void mediate(Dialog d, Frame f) {
        d.setLocationRelativeTo(f);
    }
}
